package com.quktzhuanka.app.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.quktzhuanka.app.R;
import com.quktzhuanka.app.bean.HaoDanBean;
import com.quktzhuanka.app.common.CommonUtils;
import com.quktzhuanka.app.common.SPUtils;
import com.quktzhuanka.app.utils.VerticalImageSpan;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.text.DecimalFormat;
import java.util.List;

public class NineAdapterListNew extends CommonAdapter<HaoDanBean> {
    Drawable drawable;
    SpannableString spannableString;

    DecimalFormat df=new DecimalFormat("0.00");
    public NineAdapterListNew(Context context, int layoutId, List<HaoDanBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, final HaoDanBean item, int position) {
        ImageView imageView = holder.getView(R.id.image);
        Glide.with(mContext).load(item.itempic+"_310x310.jpg").placeholder(R.drawable.no_banner).override(CommonUtils.getScreenWidth()/2,180).dontAnimate().into(imageView);

        spannableString = new SpannableString("  " + item.itemtitle);
        if ("B".equals(item.shoptype)) { //是天猫
            drawable = mContext.getResources().getDrawable(R.mipmap.label_tm);
        } else {//不是天猫
            drawable = mContext.getResources().getDrawable(R.mipmap.label_tb);
        }
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        spannableString.setSpan(new VerticalImageSpan(drawable), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ((TextView)holder.getView(R.id.title_child)).setText(spannableString);

        //券后2
        TextView tx2_2 = holder.getView(R.id.tx2_2);
        //设置删除线
        tx2_2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        tx2_2.setText("￥"+item.itemprice);
        //内部
        TextView tx3 = holder.getView(R.id.tx3);
        tx3.setText(item.couponmoney+"元券");
        //券后
        holder.setText(R.id.tx2, "￥" +item.itemendprice);
        holder.setText(R.id.tx4, "奖:"+df.format(Double.valueOf(item.tkmoney)* Double.parseDouble(df.format((float) SPUtils.getIntData(mContext, "rate", 0) / 100))));
        holder.setText(R.id.tx5,"月售"+item.itemsale);
        if(Double.valueOf(item.videoid)>0){
            holder.getView(R.id.play_img).setVisibility(View.VISIBLE);
        }else{
            holder.getView(R.id.play_img).setVisibility(View.GONE);
        }
    }
}
